//
// Created by Administrator on 2024/5/7.
//

#ifndef ZDKTVIDEOSRC_LIBYUVCONVERT_H
#define ZDKTVIDEOSRC_LIBYUVCONVERT_H


#include <stdint.h>
#include <jni.h>
#include <string.h>

class LibYUVConvert {
public:
    LibYUVConvert(int width, int height) {
        this->width = width;
        this->height = height;
        dst_y = new uint8_t[width * height];
        dst_u = new uint8_t[(width / 2) * (height / 2)];
        dst_v = new uint8_t[(width / 2) * (height / 2)];
        yuv_out = new uint8_t[getLen()];
    }

    int getLen() {
        return width * height * 3 / 2;
    }

    uint8_t *argbToI420(const uint8_t *src_argb) {
//        libyuv::ARGBToI420(src_argb,
//                           width * 4, // 源 ARGB 数据和每行的字节数
//                           dst_y, width,       // 目标 Y 数据和每行的字节数
//                           dst_u, (width / 2), // 目标 U 数据和每行的字节数
//                           dst_v, (width / 2), // 目标 V 数据和每行的字节数
//                           width,
//                           height);     // 图像的宽度和高度
//        memcpy(yuv_out, dst_y, width * height);
//        memcpy((yuv_out + width * height), dst_v, width * height / 4);
//        memcpy((yuv_out + width * height + width * height / 4), dst_u, width * height / 4);
        return yuv_out;
    }


    ~LibYUVConvert() {
        delete[] dst_y;
        delete[] dst_u;
        delete[] dst_v;
        delete[]yuv_out;
    }

private:
    int width, height;
    uint8_t *dst_y;
    uint8_t *dst_u;
    uint8_t *dst_v;
    uint8_t *yuv_out;

};


#endif //ZDKTVIDEOSRC_LIBYUVCONVERT_H
